/*
 * Author:   W.SH
 */
package com.wgg.crawler.core;

import java.util.logging.Level;
import java.util.logging.Logger;

import org.apache.http.Header;
import org.apache.http.ProtocolVersion;
import org.apache.http.StatusLine;


/**
 * 〈一句话功能简述〉<br> 
 * 〈功能详细描述〉
 *
 *  @author W.SH
 */
public class HttpSpiderResponse implements SpiderResponse {
    
    private static Logger LOG = Logger.getLogger(HttpSpiderRequest.class.getName());
    
    private String url;
    private byte[] content;
    private Header[] headers;
    private StatusLine statusLine;
    private ProtocolVersion protocolVersion;
    
    public HttpSpiderResponse() {
        
    }

    public HttpSpiderResponse(String url, String content) {
        new HttpSpiderResponse(url, content.getBytes());
    }
    
    public HttpSpiderResponse(String url, byte[] content) {
        this.url = url;
        this.content = content;
    }
    
    @Override
    public String getUrl() {
        return url;
    }

    @Override
    public byte[] getContent() {
        return content;
    }

    @Override
    public Header[] getAllHeaders() {
        return headers;
    }

    @Override
    public Header getHeader(String name) {
        if (null == name  || name.length() < 0) {
            LOG.log(Level.WARNING, "the name of header is null");
            throw new IllegalArgumentException("the name of header is null");
        }
        
        for (Header header : headers) {
            if (header.getName().equalsIgnoreCase(name)) {
                return header;
            }
        }
        return null;
    }

    @Override
    public StatusLine getStatusLine() {
        return statusLine;
    }

    @Override
    public ProtocolVersion getProtocolVersion() {
        return protocolVersion;
    }

    public static void setLog(Logger log) {
        LOG = log;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public void setContent(byte[] content) {
        this.content = content;
    }

    public void setHeaders(Header[] headers) {
        this.headers = headers;
    }

    public void setStatusLine(StatusLine statusLine) {
        this.statusLine = statusLine;
    }

    public void setProtocolVersion(ProtocolVersion protocolVersion) {
        this.protocolVersion = protocolVersion;
    }

}
